package entity

import (
	"database/sql"
	"strconv"
)

type UserCost struct {
	Cid           int     `json:"cid"`
	Uuid          string  `json:"uuid"`
	DormitoryUuid string  `json:"dormitoryUuid"`
	Username      string  `json:"username"`
	UseInfo       string  `json:"useInfo"`
	Money         float64 `json:"money"`
	CreateTime    int64   `json:"createTime"`
}

func (userCost UserCost) String() string {
	return "(" + " Cid = " + strconv.Itoa(userCost.Cid) + "," + " Uuid = " + userCost.Uuid + ","+ " DormitoryUuid = " + userCost.DormitoryUuid + "," + " Username = " + userCost.Username + "," + " UseInfo = " + userCost.UseInfo + "," + " Money = " + strconv.FormatFloat(userCost.Money, 'E', -1, 64) + "," + " CreateTime = " + strconv.FormatInt(userCost.CreateTime, 10) + " )";
}

func ReadUserCostData(rows *sql.Rows) []UserCost {
	var userCostSlice []UserCost = make([]UserCost, 0)
	for rows.Next() {
		userCost := new(UserCost)
		err := rows.Scan(&userCost.Cid, &userCost.Uuid,&userCost.DormitoryUuid, &userCost.Username, &userCost.UseInfo, &userCost.Money, &userCost.CreateTime)
		if err != nil {
			panic(err)
		}
		userCostSlice = append(userCostSlice, *userCost)
	}
	return userCostSlice
}
